/* Copyright 2001,2002,2003 NAH6
 * All Rights Reserved
 *
 * Parts Copyright DoD, Parts Copyright Starium
 *
 */
#include "main.h"
#include "move_array16.h"

/**************************************************************************
*
* ROUTINE
*               MoveArray16
*
* FUNCTION
*               copy real array to another array
*
* SYNOPSIS
*               subroutine MoveArray16(dest, source, size)
*
*   formal
*
*                       data    I/O
*       name            type    type    function
*       -------------------------------------------------------------------
*       Size            int     i       number of elements to copy
*       Source          fxpt_16 i       source
*       Dest            fxpt_16 o       destination
***************************************************************************
*
* CALLED BY
*
*       csub    psearch
*
* CALLS
*
*
**************************************************************************/
void
MoveArray16(fxpt_16 *dst, const fxpt_16 *src, int size)
{
  fxpt_16 *dst_end;
  fxpt_16 *dst_end_aligned;

  dst_end = dst + size;

  if (((long)dst & 0x2) != ((long)src & 0x2)  || size < 2) {
    while (dst != dst_end)
      *dst++ = *src++;
    return;
  }

  if (((long)dst & 0x2) != 0) {    /* src/dst have mid word alignment */
    *dst++ = *src++;
  }

  dst_end_aligned = (fxpt_16 *)((unsigned long)dst_end & ~0x2);

  /*
   *  src/dst start and end are all word aligned if we get here!
   */
  while (dst != dst_end_aligned) {
    *(uint32 *)dst = *(uint32 *)src;
    src += 2;
    dst += 2;
  }

  if (dst != dst_end) {
    *dst = *src;
  }
}
